﻿'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'


Imports DotNetNuke.Modules.Announcements.Components.BaseClasses
Imports DotNetNuke.Modules.Announcements.Components.Business
Imports DotNetNuke
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.UI.Utilities
Imports DotNetNuke.Modules.Workflow
Imports DotNetNuke.Security.Permissions
Imports utils = DotNetNuke.Common.Utilities
Imports System.Globalization
Imports System.Web.UI.WebControls

''' <summary>
''' The EditAnnounucements PortalModuleBase is used to manage Announcements
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[cnurse]	9/20/2004	Moved Announcements to a separate Project
''' 	[cnurse]	9/20/2004	Updated to reflect design changes for Help, 508 support
'''                       and localisation
''' 	[erikvb]	11/20/2007	updated for version 4.0.0 of the module
'''     [erikvb]    10/20/2008  updated for version 4.0.2 of the module
''' </history>
Partial Class EditAnnouncements

    Inherits AnnouncementsBase

#Region " Private Members"

    Private WorkflowID As Integer = -1
    Private itemId As Integer
    Private is24HourClock As Boolean = String.IsNullOrEmpty(CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator)

#End Region

#Region "Private Methods"

    Private Sub AddWorkflowLog(ByVal objContent As AnnouncementInfo)
        ' add log history
        Dim objLog As New Workflow.WorkflowLogInfo
        objLog.ModuleID = ModuleId
        objLog.ItemID = objContent.ItemId
        objLog.StateID = objContent.StateID
        objLog.Approved = objContent.Approved
        objLog.Comment = objContent.Comment

        Dim objLogs As New Workflow.WorkflowLogController
        objLogs.Add(objLog)

        Dim objAnnouncements As New AnnouncementsController
        objAnnouncements.DeleteAnnouncementUsers()
        objContent = objAnnouncements.GetAnnouncement(objContent.ItemId, objContent.ModuleId)

        ' create user notifications
        objLogs.CreateUserNotifications(PortalId, objContent.ModuleId, objContent.ItemId, objContent.CreatedByUserID, objContent.WorkflowID, objContent.StateID, objContent.StateName, objContent.IsPublished, objContent.Notify)

    End Sub

    Private Sub DisplayHistory(ByVal objContent As AnnouncementInfo)
        Dim objLog As New Workflow.WorkflowLogController
        lblVersion.Text = objContent.Version.ToString()
        lblWorkflow.Text = objContent.WorkflowName 'Localization.GetString(objContent.WorkflowName, Me.LocalResourceFile)
        lblState.Text = objContent.StateName 'Localization.GetString(objContent.StateName, Me.LocalResourceFile)

        grdLog.DataSource = objLog.Get(objContent.ModuleId, objContent.ItemId)
        grdLog.DataBind()
    End Sub

    Private Sub DisplayPreview(ByVal objContent As AnnouncementInfo)
        Dim output As New Text.StringBuilder

        Dim dnnTokenReplace As Services.Tokens.TokenReplace = Nothing
        If Template.TokenReplaceNeeded Then
            dnnTokenReplace = New Services.Tokens.TokenReplace(Services.Tokens.Scope.DefaultSettings, CultureInfo.CurrentCulture.Name, PortalSettings, UserInfo)
        End If
        Dim altItemTemplateAvailable As Boolean = Not String.IsNullOrEmpty(Template.AltItemTemplate)
        If dnnTokenReplace IsNot Nothing Then
            output.Append(dnnTokenReplace.ReplaceEnvironmentTokens(Template.HeaderTemplate))
        End If

        Dim tokenReplace As New Components.Templating.AnnouncementsTokenReplace()

        'we have to pass IsEditable to the announcement, because it is used to draw the edit icon
        objContent.IsEditable = False
        objContent.IsPublished = True

        'Create a Token Replace and replace the tokens for this template
        tokenReplace.SetPropertySource(objContent)

        output.Append(tokenReplace.ReplaceAnnouncmentTokens(Template.ItemTemplate))


        'Next
        If dnnTokenReplace IsNot Nothing Then
            output.Append(dnnTokenReplace.ReplaceEnvironmentTokens(Template.FooterTemplate))
        End If

        lblPreview.Controls.Add(New Web.UI.LiteralControl(output.ToString()))
    End Sub

#End Region

#Region " Event Handlers"

    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        ' localize datagrids
        DotNetNuke.Services.Localization.Localization.LocalizeDataGrid(grdLog, Me.LocalResourceFile)
        DotNetNuke.Services.Localization.Localization.LocalizeDataGrid(grdVersions, Me.LocalResourceFile)

    End Sub

    ''' <summary>
    ''' Page_Load runs when the control is loaded
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            WorkflowID = WorkflowSettingsController.GetWorkflow(ModuleId, TabId, PortalId).Value

            ' first check review security
            If Request.QueryString("viewtype").ToUpper = "REVIEW" AndAlso WorkflowSettingsController.CouldReview(WorkflowID, Me.ModuleConfiguration) = False Then
                Response.Redirect(AccessDeniedURL(), True)
            End If

            If Request.QueryString("viewtype").ToUpper = "EDIT" AndAlso ModulePermissionController.CanEditModuleContent(Me.ModuleConfiguration) = False Then
                Response.Redirect(AccessDeniedURL(), True)
            End If

            ' get itemid
            If Not (Request.QueryString("ItemId") Is Nothing) Then
                itemId = Int32.Parse(Request.QueryString("ItemId"))
            Else
                itemId = Convert.ToInt32(Common.Utilities.Null.NullInteger)
            End If

            cmdCalendar.NavigateUrl = utils.Calendar.InvokePopupCal(txtPublishDate)
            cmdCalendar2.NavigateUrl = utils.Calendar.InvokePopupCal(txtExpireDate)

            If (Settings.Contains("editorHeight")) AndAlso (Settings("editorHeight").ToString <> "") Then
                Me.teDescription.Height = Integer.Parse(Settings("editorHeight").ToString)
            Else
                Me.teDescription.Height = 300
            End If

            If Page.IsPostBack = False Then
                urlImage.FileFilter = glbImageFileTypes
                urlImage.ShowNone = True

                ctlURL.ShowLog = True
                ctlURL.ShowNewWindow = True
                ctlURL.ShowTrack = True
                ctlURL.ShowUsers = True

                ' delete confirmation
                ClientAPI.AddButtonConfirm(cmdDelete, Localization.GetString("DeleteItem"))


                InitializeHours(ddlHoursPublish)
                InitializeMinutes(ddlMinutesPublish)
                InitializeAmPm(ddlAmPmPublish, phAmPmPublish)

                InitializeHours(ddlHoursExpire)
                InitializeMinutes(ddlMinutesExpire)
                InitializeAmPm(ddlAmPmExpire, phAmPmExpire)

                ' load states for workflow
                Dim objWorkflow As New Workflow.WorkflowStateController
                Dim arrStates As ArrayList = objWorkflow.GetWorkflowStates(WorkflowID)

                ' direct publish workflows do not need the Publish checkbox option
                If arrStates.Count = 1 Then
                    rowPublish.Visible = False
                    cmdDelete.Visible = True
                Else
                    rowPublish.Visible = True
                    cmdDelete.Visible = Workflow.WorkflowSettingsController.CanReview(objWorkflow.GetLastWorkflowStateID(WorkflowID), WorkflowID, Me.ModuleConfiguration)
                End If

                If Not Common.Utilities.Null.IsNull(itemId) Then

                    ' get object
                    Dim objAnnouncements As New AnnouncementsController
                    Dim objAnnouncement As AnnouncementInfo = objAnnouncements.GetTopAnnouncement(ModuleId, False, WorkflowID, itemId)

                    If Not objAnnouncement Is Nothing Then

                        ' check review security
                        If Request.QueryString("viewtype").ToUpper = "REVIEW" AndAlso Not Workflow.WorkflowSettingsController.CanReview(objAnnouncement.StateID, objAnnouncement.WorkflowID, Me.ModuleConfiguration) Then
                            Response.Redirect(AccessDeniedURL(), True)
                        End If

                        ' populate controls
                        txtTitle.Text = objAnnouncement.Title.ToString
                        urlImage.Url = objAnnouncement.ImageSource
                        teDescription.Text = objAnnouncement.Description
                        teSummary.Text = objAnnouncement.Summary
                        ctlURL.Url = objAnnouncement.Url
                        If Not Common.Utilities.Null.IsNull(objAnnouncement.ViewOrder) Then
                            txtViewOrder.Text = Convert.ToString(objAnnouncement.ViewOrder)
                        End If
                        SetDateTimeValue(objAnnouncement.PublishDate, txtPublishDate, ddlHoursPublish, ddlMinutesPublish, ddlAmPmPublish)
                        SetDateTimeValue(objAnnouncement.ExpireDate, txtExpireDate, ddlHoursExpire, ddlMinutesExpire, ddlAmPmExpire)

                        ctlAudit.Entity = objAnnouncement

                        ctlTracking.URL = objAnnouncement.Url
                        ctlTracking.ModuleID = ModuleId

                        grdVersions.DataSource = objAnnouncements.GetAllAnnouncements(ModuleId, itemId)
                        grdVersions.DataBind()

                        DisplayHistory(objAnnouncement)
                        DisplayPreview(objAnnouncement)

                    Else ' security violation attempt to access item not related to this Module
                        Response.Redirect(NavigateURL(), True)
                    End If
                Else ' new item
                    txtPublishDate.Text = DateTime.Today.ToShortDateString
                    cmdDelete.Visible = False
                    ctlAudit.Visible = False
                    ctlTracking.Visible = False
                End If


                ' handle Edit and Review actions
                Select Case Request.QueryString("viewtype").ToUpper
                    Case "EDIT"
                        dshReview.Visible = False
                        divReview.Visible = False
                    Case "REVIEW"
                        pnlEdit.Visible = False
                        dshVersions.Visible = False
                        tblVersions.Visible = False
                        dshPreview.IsExpanded = True
                        If Request.QueryString("action").ToUpper = "APPROVE" Then
                            cmdReview.Text = Localization.GetString("ApproveContent.Action", LocalResourceFile)
                        Else
                            cmdReview.Text = Localization.GetString("RejectContent.Action", LocalResourceFile)
                        End If
                End Select

            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    ''' <summary>
    ''' cmdCancel_Click runs when the cancel button is clicked
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdCancel.Click
        Try
            Response.Redirect(NavigateURL(), True)
        Catch exc As Exception           'Module failed to load
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    ''' <summary>
    ''' cmdDelete_Click runs when the delete button is clicked
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cmdDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDelete.Click
        Try
            If Not Common.Utilities.Null.IsNull(itemId) Then
                ' delete item
                Dim objAnnouncements As New AnnouncementsController
                objAnnouncements.DeleteAnnouncement(ModuleId, itemId)
                ' refresh cache
                ModuleController.SynchronizeModule(ModuleId)
            End If

            ' redirect back to page
            Response.Redirect(NavigateURL(), True)
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    ''' <summary>
    ''' cmdUpdate_Click runs when the update button is clicked
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUpdate.Click
        Try
            ' verify data
            If Page.IsValid = True Then
                Dim objWorkflow As New Workflow.WorkflowStateController

                Dim objAnnouncements As New AnnouncementsController
                Dim objAnnouncement As AnnouncementInfo = objAnnouncements.GetTopAnnouncement(ModuleId, False, WorkflowID, itemId)
                If objAnnouncement Is Nothing Then
                    objAnnouncement = New AnnouncementInfo
                    objAnnouncement.ItemId = itemId
                End If
                'objAnnouncement = CType(CBO.InitializeObject(objAnnouncement, GetType(AnnouncementInfo)), AnnouncementInfo)

                ' populate object
                objAnnouncement.ParentItemId = itemId
                objAnnouncement.ModuleId = ModuleId
                objAnnouncement.Title = txtTitle.Text
                objAnnouncement.ImageSource = urlImage.Url
                objAnnouncement.Description = teDescription.Text
                objAnnouncement.Summary = teSummary.Text
                objAnnouncement.Url = ctlURL.Url
                objAnnouncement.PublishDate = GetDateTimeValue(txtPublishDate, ddlHoursPublish, ddlMinutesPublish, ddlAmPmPublish)
                objAnnouncement.ExpireDate = GetDateTimeValue(txtExpireDate, ddlHoursExpire, ddlMinutesExpire, ddlAmPmExpire)

                If txtViewOrder.Text <> "" Then
                    objAnnouncement.ViewOrder = Convert.ToInt32(txtViewOrder.Text)
                End If

                'set the initial workflow sate
                objAnnouncement.StateID = objWorkflow.GetFirstWorkflowStateID(WorkflowID)
                objAnnouncement.WorkflowID = WorkflowID

                ' publish content
                If rowPublish.Visible = True AndAlso chkPublish.Checked Then
                    objAnnouncement.StateID = objWorkflow.GetNextWorkflowStateID(WorkflowID, objAnnouncement.StateID)
                End If

                ' determine if content is published
                objAnnouncement.IsPublished = (objAnnouncement.StateID = objWorkflow.GetLastWorkflowStateID(objAnnouncement.WorkflowID))

                Dim blnCreateNewVersion As Boolean = False

                ' determine if we are creating a new version of content or updating an existing version
                If Not Common.Utilities.Null.IsNull(itemId) Then
                    If objAnnouncement.WorkflowName <> "[REPAIR_WORKFLOW]" Then
                        Dim objContent As AnnouncementInfo = objAnnouncements.GetTopAnnouncement(objAnnouncement.ModuleId, False, objAnnouncement.WorkflowID, itemId)
                        If Not objContent Is Nothing Then
                            If objContent.StateID = objWorkflow.GetLastWorkflowStateID(objAnnouncement.WorkflowID) Then
                                blnCreateNewVersion = True
                            End If
                        End If
                    End If
                Else
                    blnCreateNewVersion = True
                End If

                ' add or update
                If blnCreateNewVersion Then
                    objAnnouncements.AddAnnouncement(objAnnouncement, UserInfo.UserID)
                Else
                    objAnnouncements.UpdateAnnouncement(objAnnouncement, UserInfo.UserID, Workflow.WorkflowSettingsController.GetMaximumVersionHistory(PortalId))
                End If

                'add workflow log
                AddWorkflowLog(objAnnouncement)

                ' refresh output cache
                ModuleController.SynchronizeModule(ModuleId)

                ' url tracking
                Dim objUrls As New UrlController
                objUrls.UpdateUrl(PortalId, ctlURL.Url, ctlURL.UrlType, ctlURL.Log, ctlURL.Track, ModuleId, ctlURL.NewWindow)

                ' redirect back to page
                Response.Redirect(NavigateURL(), True)

            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Private Sub cmdCancel2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancel2.Click
        Response.Redirect(NavigateURL(Me.TabId))
    End Sub

    Private Sub cmdReview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdReview.Click
        Try
            Dim blnIsApproved As Boolean = (Request.QueryString("action").ToUpper = "APPROVE")

            ' approve content
            Dim objAnnouncements As New AnnouncementsController
            Dim objWorkflow As New Workflow.WorkflowStateController
            Dim objContent As AnnouncementInfo = objAnnouncements.GetTopAnnouncement(ModuleId, False, WorkflowID, itemId)

            ' if the user has permissions to review the content
            If Workflow.WorkflowSettingsController.CanReview(objContent.StateID, WorkflowID, Me.ModuleConfiguration) Then
                If blnIsApproved Then
                    ' promote to next state
                    objContent.ModuleId = ModuleId
                    objContent.WorkflowID = WorkflowID
                    objContent.StateID = objWorkflow.GetNextWorkflowStateID(WorkflowID, objContent.StateID)
                    objContent.Comment = txtComment.Text

                    ' determine if content is published
                    objContent.IsPublished = (objContent.StateID = objWorkflow.GetLastWorkflowStateID(objContent.WorkflowID))


                    objAnnouncements.UpdateAnnouncement(objContent, UserId, Workflow.WorkflowSettingsController.GetMaximumVersionHistory(PortalId))

                    'add workflow log
                    AddWorkflowLog(objContent)

                    ' refresh output cache
                    ModuleController.SynchronizeModule(ModuleId)

                    ' redirect back to portal
                    Response.Redirect(NavigateURL(), True)
                Else
                    ' rejections must have a comment
                    If txtComment.Text <> "" Then
                        ' reset to first state
                        objContent.ModuleId = ModuleId
                        objContent.WorkflowID = WorkflowID
                        objContent.StateID = objWorkflow.GetFirstWorkflowStateID(WorkflowID)
                        objContent.Comment = txtComment.Text
                        objContent.Approved = False
                        objAnnouncements.UpdateAnnouncement(objContent, UserId, Workflow.WorkflowSettingsController.GetMaximumVersionHistory(PortalId))

                        'add workflow log
                        AddWorkflowLog(objContent)

                        ' redirect back to portal
                        Response.Redirect(NavigateURL(), True)
                    Else
                        UI.Skins.Skin.AddModuleMessage(Me, Services.Localization.Localization.GetString("RejectMessage", Me.LocalResourceFile), UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
                    End If
                End If
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

#End Region

#Region " DateTime field Methods"

    ''' <summary>
    ''' InitializeMinutes initializes the minutes dropdown
    ''' </summary>
    ''' <param name="MinutesDropDown"></param>
    ''' <remarks></remarks>
    Private Sub InitializeMinutes(ByVal MinutesDropDown As DropDownList)
        'setup minutes dropdown
        For i As Integer = 0 To 59
            MinutesDropDown.Items.Add(New ListItem(i.ToString("00"), i.ToString()))
        Next i
    End Sub
    ''' <summary>
    ''' InitializeHours initializes the hours dropdown based on whether the culture has 24 hour clock or 12 hour
    ''' </summary>
    ''' <param name="HoursDropDown"></param>
    ''' <remarks></remarks>
    Private Sub InitializeHours(ByVal HoursDropDown As DropDownList)
        Dim maxHour As Integer = 12
        Dim minHour As Integer = 1
        If is24HourClock Then
            minHour = 0
            maxHour = 23
        End If
        For i As Integer = minHour To maxHour
            If (i = 12) Then
                If is24HourClock Then
                    HoursDropDown.Items.Add(New ListItem(i.ToString("00"), i.ToString()))
                Else
                    HoursDropDown.Items.Insert(0, New ListItem(i.ToString("00"), i.ToString()))
                End If
            Else
                HoursDropDown.Items.Add(New ListItem(i.ToString("00"), i.ToString()))
            End If
        Next i
    End Sub
    ''' <summary>
    ''' if cullture has 12 hour clock InitializeAmPm initializes the am/pm dropdown
    ''' </summary>
    ''' <param name="AmPmDropDown"></param>
    ''' <param name="AmPmPlaceHolder"></param>
    ''' <remarks></remarks>
    Private Sub InitializeAmPm(ByVal AmPmDropDown As DropDownList, ByVal AmPmPlaceHolder As PlaceHolder)
        If Not is24HourClock Then
            'setup am/pm
            AmPmPlaceHolder.Visible = True
            AmPmDropDown.Items.Add(New ListItem(CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator, "AM"))
            AmPmDropDown.Items.Add(New ListItem(CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator, "PM"))
        Else
            AmPmPlaceHolder.Visible = False
        End If
    End Sub
    ''' <summary>
    ''' set values of datetime dropdowns and text field
    ''' </summary>
    ''' <param name="Value"></param>
    ''' <param name="DateText"></param>
    ''' <param name="HoursDropDown"></param>
    ''' <param name="MinutesDropDown"></param>
    ''' <param name="AmPmDropDown"></param>
    ''' <remarks></remarks>
    Private Sub SetDateTimeValue(ByVal Value As DateTime, ByVal DateText As TextBox, ByVal HoursDropDown As DropDownList, ByVal MinutesDropDown As DropDownList, ByVal AmPmDropDown As DropDownList)
        If Value <> Null.NullDate Then
            DateText.Text = Value.ToShortDateString()

            Dim hour As Integer = Value.Hour
            Dim minute As Integer = Value.Minute
            Dim isAM As Boolean = True

            If Not is24HourClock Then
                If hour >= 12 Then
                    hour -= 12
                    isAM = False
                End If
                If hour = 0 Then
                    hour = 12
                End If
            End If

            If HoursDropDown.Items.FindByValue(hour.ToString()) IsNot Nothing Then
                HoursDropDown.Items.FindByValue(hour.ToString()).Selected = True
            End If

            If MinutesDropDown.Items.FindByValue(minute.ToString()) IsNot Nothing Then
                MinutesDropDown.Items.FindByValue(minute.ToString()).Selected = True
            End If
            If Not is24HourClock Then
                If isAM Then
                    AmPmDropDown.SelectedIndex = 0
                Else
                    AmPmDropDown.SelectedIndex = 1
                End If
            End If
        End If
    End Sub

    ''' <summary>
    ''' get values of date field and time dropdowns in one datetimxe value
    ''' </summary>
    ''' <param name="DateText"></param>
    ''' <param name="HoursDropDown"></param>
    ''' <param name="MinutesDropDown"></param>
    ''' <param name="AmPmDropDown"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetDateTimeValue(ByVal DateText As TextBox, ByVal HoursDropDown As DropDownList, ByVal MinutesDropDown As DropDownList, ByVal AmPmDropDown As DropDownList) As DateTime
        Dim returnValue As DateTime = Null.NullDate
        If Not String.IsNullOrEmpty(DateText.Text) Then
            returnValue = DateTime.Parse(DateText.Text, CultureInfo.CurrentCulture)
            If HoursDropDown.SelectedValue <> "12" OrElse is24HourClock Then
                returnValue = returnValue.AddHours(Int32.Parse(HoursDropDown.SelectedValue))
            End If
            returnValue = returnValue.AddMinutes(Int32.Parse(MinutesDropDown.SelectedValue))

            If Not is24HourClock AndAlso AmPmDropDown.SelectedValue.Equals("PM") Then
                returnValue = returnValue.AddHours(12)
            End If
        End If
        Return returnValue
    End Function
#End Region

   
End Class